package acm.天梯赛练习2;
import java.util.Scanner;

public class J {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        while (n-- > 0) {
            String s = sc.nextLine();
            System.out.println(fun(new StringBuilder(s)));
        }
    }
    public static String fun(StringBuilder str){
        if (str.length()<=0){
            return "";
        }
        char c = str.charAt(0);
        str.deleteCharAt(0);
        String res="";
        if (c>=48&&c<58){
            int n=c-48;
            c= str.charAt(0);
            str.deleteCharAt(0);
            int i = 0;
            if(c=='('){
                int index=1;
                for (; i < str.length(); i++) {
                    if (str.charAt(i)=='('){
                        index++;
                    }else if (str.charAt(i)==')'){
                        index--;
                    }
                    if (index==0){
                        break;
                    }
                }
                for (int j = 0; j < n; j++) {
                    res+=fun(new StringBuilder(str.substring(0,i)));
                }
                str.deleteCharAt(i);    //删掉右括号
            }else {
                for (int j = 0; j < n; j++) {
                    res+=c;
                }
            }
            res+=fun(new StringBuilder(str.substring(i,str.length())));
        }else{
            res=c+fun(str);
        }
        return res;
    }
}
